import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class CartService {

  CartList:Array<{goods:Parse.Object, count:number}> = []
  constructor() { 
  }
  addGoodsToCart(goods:Parse.Object|null, count:number){
    if(goods!=null){
      let exists = this.CartList.find(item=>item.goods.id==goods.id)
      if(exists?.goods){
        exists.count += count
        return // 存在同一个商品，只增加数字，不做新增直接返回
      }
      this.CartList.push({
        goods:goods,
        count:count
      })
    }
  }
}
